package com.gbiac.modules.monitor.controller;

import com.gbiac.modules.monitor.model.dto.AIDeviceCallbackAFRParamDTO;
import com.gbiac.modules.monitor.model.dto.AiDeviceCallbackAFRResponseDTO;
import com.gbiac.modules.monitor.model.form.AiWarnMessageForm;
import com.gbiac.modules.monitor.service.AiDeviceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.util.DateUtils;
import org.jeecg.config.shiro.IgnoreAuth;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Calendar;

@Api(tags="AI设备对接接口")
@RestController
@RequestMapping("/aiDevice")
@Slf4j
public class AiDeviceController {

    @Resource
    AiDeviceService aiDeviceService;

    @IgnoreAuth
    @ApiOperation(value="添加AI告警信息", notes="添加AI告警信息")
    @PostMapping(value = "/addAiWarnMessage")
    public Result<String> addAiWarnMessage(@RequestBody AiWarnMessageForm aiWarnMessageForm) {
        try {
            aiDeviceService.addAiWarnMessage(aiWarnMessageForm);
            return Result.OK();
        }catch (Exception e){
            e.printStackTrace();
            return Result.error(e.getMessage());
        }
    }


    @IgnoreAuth
    @ApiOperation(value="人脸识别结果回调", notes="人脸识别结果回调")
    @PostMapping(value = "/callbackAFR")
    public Result<Object> callbackAFR(@RequestBody AIDeviceCallbackAFRParamDTO aiDeviceCallbackAFRParamDTO) {
        try {
            return Result.OK(aiDeviceService.callbackAFR(aiDeviceCallbackAFRParamDTO));
        }catch (Exception e){
            e.printStackTrace();
            return Result.error(e.getMessage(),new AiDeviceCallbackAFRResponseDTO(0));
        }
    }


    @IgnoreAuth
    @ApiOperation(value="checkRule", notes="checkRule")
    @PostMapping(value = "/checkRule")
    public Result<Object> checkRule(@RequestBody  AiWarnMessageForm aiWarnMessageForm) {
        try {
            return Result.OK(aiDeviceService.checkRule(aiWarnMessageForm));
        }catch (Exception e){
            e.printStackTrace();
            return Result.error(e.getMessage(),new AiDeviceCallbackAFRResponseDTO(0));
        }
    }
    public static void main(String[] args) {
        Calendar c = Calendar.getInstance();
        c.set(Calendar.HOUR_OF_DAY, Integer.parseInt("03"));
        c.set(Calendar.MINUTE, Integer.parseInt("11"));
        System.out.println(DateUtils.formatDate(c.getTime(), "yyyy-MM-dd HH:mm:ss"));
        System.out.println(c.getTime().getTime());
    }
}
